package com.dmgis.qxfw.dataservice.businessservice.infoinquiry.service.impl;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.*;

import com.dmgis.qxfw.dataservice.businessservice.api.domain.DbConfig;
import com.dmgis.qxfw.dataservice.businessservice.api.domain.RequestDataBySelect;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.qx.*;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.zy.*;
import com.dmgis.qxfw.dataservice.businessservice.api.entity.yj.*;
import com.dmgis.qxfw.dataservice.businessservice.common.entity.MediumSmallScale;
import com.dmgis.qxfw.dataservice.businessservice.common.entity.ZhdPagingModel;
import com.dmgis.qxfw.dataservice.businessservice.common.entity.lvyou;
import com.dmgis.qxfw.dataservice.businessservice.common.util.DateTime;
import com.dmgis.qxfw.dataservice.businessservice.common.util.FileUtil;
import com.dmgis.qxfw.dataservice.businessservice.common.util.WebCtrlData;
import com.dmgis.qxfw.dataservice.businessservice.controller.ProcessRequestController;
import com.dmgis.qxfw.dataservice.businessservice.dmgis_mongodb_srv.dataservice.service.Impl.FileRequestService;
import com.dmgis.qxfw.dataservice.businessservice.dmgis_mongodb_srv.dataservice.service.Impl.MongoService1;
import com.dmgis.qxfw.dataservice.businessservice.infoinquiry.service.InformationQueryService;
import com.dmgis.qxfw.dataservice.commonservice.utils.JsonUtil;
import com.dmgis.qxfw.dataservice.commonservice.utils.StringUtil;
import org.springframework.stereotype.Service;
import com.fasterxml.jackson.core.type.TypeReference;

import javax.servlet.http.HttpServletRequest;

@Service("InfoService")
public class InformationQueryServiceImpl implements InformationQueryService {

    ProcessRequestController pc = new ProcessRequestController();

    //MongoService1 ms = new MongoService1();
    FileRequestService ms = new FileRequestService();
    @Override
    public tour_fcst getTownshipForecastTempTime() {
        // TODO 获取旅游最新时间
        tour_fcst result = new tour_fcst();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"to_char(datechar,'yyyy-MM-dd 00:00:00') as dateChar", "timechar"};
        selectRequest.setColumns(columns);
        selectRequest.setSort(new String[]{"datechar desc", "timechar desc"});
        selectRequest.setLimit(1);
        // 条件where
        StringBuilder strWhere = new StringBuilder();
        strWhere.append(String.format(" ntimes<=72 and forecasttype='12'"));
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "tour_fcst");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            result = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<tour_fcst>>() {
            }).get(0);
        } catch (Exception e) {
            result.setDatechar(DateTime.now().toDate());
        }
        return result;
    }

    @Override
    public forecastinfotemp getInitCityMaxTime() {
        // TODO 获取城镇预报最新时间
        forecastinfotemp result = new forecastinfotemp();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"to_char(datechar,'yyyy-MM-dd 00:00:00') as dateChar", "timechar"};
        selectRequest.setColumns(columns);
        selectRequest.setParam(String.format("city like '%s%%'", DbConfig.CITY));
        selectRequest.setSort(new String[]{"datechar desc", "timechar desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "forecastinfo");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            result = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<forecastinfotemp>>() {}).get(0);
        } catch (Exception e) {
            result.setDatechar(DateTime.now().toDate());
        }
        return result;
    }

    @Override
    public List<forecastinfotemp> weather(forecastinfotemp selectKey) {


        return null;
    }


    @Override
    public List<township_station> getloadCityStation() {
        // TODO 城镇预报站点信息
        List<township_station> resultList = new ArrayList<township_station>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 条件where
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        strWhere.append(String.format(" and stationid like '5%%'"));
        strWhere.append(" and city like '" + DbConfig.CITY + "%'");
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"stationid desc"});
        try {
            selectParam.put("method", "smallscale_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<township_station>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        return resultList;
    }

    @Override
    public List<forecastinfotemp> getCityForecast(forecastinfotemp selectKey, String type) {
        // TODO 城镇预报查询
        List<forecastinfotemp> resultList = new ArrayList<forecastinfotemp>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("ntimes");
        columns.add("weather1");
        columns.add("weather2");
        columns.add("CAST(maxtemp as numeric(18,1)) as maxtemp");
        columns.add("CAST(minTemp as numeric(18,1)) as minTemp");
        columns.add("wind1");
        columns.add("wind2");
        columns.add("windd1");
        columns.add("windd2");
        columns.add("rain");
        columns.add("maxhumid");
        columns.add("datechar");
        columns.add("timechar");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        if (type.equals("weather") || type == "weather") {
            selectRequest.setLimit(1);
        }
        // 条件where
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(selectKey.getStationid())) {
            strWhere.append(String.format("and stationid='%s'", selectKey.getStationid()));
        }
        if (selectKey.getDatechar() != null) {
            strWhere.append(String.format(" and datechar='%tF'", selectKey.getDatechar()));
        }
        if (!StringUtil.IsNullOrEmpty(selectKey.getTimechar())) {
            strWhere.append(String.format(" and timechar='%s'", selectKey.getTimechar()));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        if (type.equals("weather") || type == "weather") {
            strWhere.append(String.format(" and city like '" + DbConfig.CITY + "%'"));
        } else {
            strWhere.append(String.format(" and city like '%s%%'", DbConfig.CITY));
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"stationid asc", "ntimes asc"});
        try {
            if (DateTime.UserMainDataTable(selectKey.getDatechar(), DbConfig.CACHEDAYS)) {
                selectParam.put("method", "forecastinfo");
            } else {
                selectParam.put("method", "forecastinfo");
            }
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<forecastinfotemp>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return resultList;
    }
    @Override
    public List<forecastinfotemp> get5DayInfo(forecastinfotemp selectKey, String type) {
        // TODO 未来五天预报查询
        List<forecastinfotemp> resultList = new ArrayList<forecastinfotemp>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("ntimes");
        columns.add("weather1");
        columns.add("weather2");
        columns.add("CAST(maxtemp as numeric(18,1)) as maxtemp");
        columns.add("CAST(minTemp as numeric(18,1)) as minTemp");
        columns.add("wind1");
        columns.add("wind2");
        columns.add("windd1");
        columns.add("windd2");
        columns.add("rain");
        columns.add("maxhumid");
        columns.add("datechar");
        columns.add("timechar");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        if (type.equals("weather") || type == "weather") {
            selectRequest.setLimit(1);
        }
        // 条件where
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(selectKey.getStationid())) {
            strWhere.append(String.format("and stationid='%s'", selectKey.getStationid()));
        }
        if (selectKey.getDatechar() != null) {
            strWhere.append(String.format(" and datechar='%tF'", selectKey.getDatechar()));
        }
        if (!StringUtil.IsNullOrEmpty(selectKey.getTimechar())) {
            strWhere.append(String.format(" and timechar='%s'", selectKey.getTimechar()));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        if (type.equals("weather") || type == "weather") {
            strWhere.append(String.format(" and city like '" + DbConfig.CITY + "%'"));
        } else {
            strWhere.append(String.format(" and city like '%s%%'", DbConfig.CITY));
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"stationid asc", "ntimes asc Limit 5"});
        try {
            if (DateTime.UserMainDataTable(selectKey.getDatechar(), DbConfig.CACHEDAYS)) {
                selectParam.put("method", "forecastinfo");
            } else {
                selectParam.put("method", "forecastinfo");
            }
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<forecastinfotemp>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return resultList;
    }
    @Override
    public township_forecasttemp getInitFineMaxTime() {
        // TODO 获取精细化预报最新时间
        township_forecasttemp result = new township_forecasttemp();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"to_char(datechar,'yyyy-MM-dd 00:00:00') as dateChar", "timechar"};
        selectRequest.setColumns(columns);
        selectRequest.setParam(String.format("city like '%s%%'", DbConfig.CITY));
        selectRequest.setSort(new String[]{"datechar desc", "timechar desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "township_forecast");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            result = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<township_forecasttemp>>() {
            }).get(0);
        } catch (Exception e) {
            result.setDatechar(DateTime.now().toDate());
        }
        return result;
    }

    @Override
    public List<township_station> getloadFineStation() {
        // TODO 精细化预报站点信息
        List<township_station> resultList = new ArrayList<township_station>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setColumns(new String[]{"DISTINCT stationname","stationid","longitude","latitude"});
        // 条件where
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        strWhere.append(" and city like '" + DbConfig.CITY + "%' ");
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "township_station");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<township_station>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        return resultList;
    }

    @Override
    public List<township_forecasttemp> getFineForecast(township_forecasttemp selectKey) {
        // TODO 精细化预报查询
        List<township_forecasttemp> resultList = new ArrayList<township_forecasttemp>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("ntimes");
        columns.add("weather1");
        columns.add("stationid");
        columns.add("to_char(datechar,'yyyy-MM-dd 00:00:00') as dateChar");
        columns.add("timechar");
        columns.add("CAST(maxtemp as numeric(18,1)) as maxtemp");
        columns.add("CAST(minTemp as numeric(18,1)) as minTemp");
        columns.add("winds");
        columns.add("windd");
        columns.add("press");
        columns.add("humid");
        columns.add("rain");
        columns.add("remark");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 条件where
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(selectKey.getStationid())) {
            strWhere.append(String.format("and stationid ='%s'", selectKey.getStationid()));
        }
        if (selectKey.getDatechar() != null) {
            strWhere.append(String.format(" and datechar ='%tF'", selectKey.getDatechar()));
        }
        if (!StringUtil.IsNullOrEmpty(selectKey.getTimechar())) {
            strWhere.append(String.format(" and timechar ='%s'", selectKey.getTimechar()));
        }
        strWhere.append(String.format(" and ntimes >=12 and ntimes <=168"));
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        strWhere.append(" and city like '" + DbConfig.CITY + "%'");
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"stationid asc,ntimes asc"});
        try {
            if (DateTime.UserMainDataTable(selectKey.getDatechar(), DbConfig.CACHEDAYS)) {
                selectParam.put("method", "township_forecast");
            } else {
                selectParam.put("method", "township_forecast");
            }
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<township_forecasttemp>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return resultList;
    }

    @Override
    public List<doppler> getRadHour(String radid, String radtype, String yangjiao) {
        // TODO 获取雷达图小时
        List<doppler> resultList = new ArrayList<doppler>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("to_char(datechar, 'yyyy-MM-dd HH24:MI:SS') as datechar");
        columns.add("TimeChar");
        columns.add("StationId");
        columns.add("LdType");
        columns.add("Elevation");
        columns.add("Path");
        columns.add("RadTitle");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 条件where
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(radid)) {
            strWhere.append(String.format(" stationid = '%s'", radid));
            whereCount++;
        }
        if (!StringUtil.IsNullOrEmpty(radtype)) {
            strWhere.append(String.format(" and ldtype = '%s'", radtype));
        }
        if (!StringUtil.IsNullOrEmpty(yangjiao)) {
            strWhere.append(String.format(" and elevation = '%s'", yangjiao));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"datechar desc", "timechar desc"});
        selectRequest.setLimit(10);
        try {
            selectParam.put("method", "doppler");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<doppler>>() {
            });
        } catch (Exception e) {
            e.getMessage();
        }
        return resultList;
    }

    @Override
    public List<satellitenephoram> getCloudHour(String cloudtype) {
        // TODO 获取云图小时
        List<satellitenephoram> resultList = new ArrayList<satellitenephoram>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("to_char(datechar, 'yyyy-MM-dd HH24:MI:SS') as datechar");
        columns.add("TimeChar");
        columns.add("ytType");
        columns.add("Path");
        columns.add("SateTitle");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 条件where
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        strWhere.append(String.format(" and yttype = '%s'", cloudtype));
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"datechar desc", "timechar desc"});
        selectRequest.setLimit(10);
        try {
            selectParam.put("method", "satellitenephoram");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<satellitenephoram>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        return resultList;
    }

    @Override
    public List<msgmediumsmallscale> getRainMax(String startT, String t) {
        // TODO 自动站--最大雨量
        List<msgmediumsmallscale> resultList = new ArrayList<msgmediumsmallscale>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("rain");
        columns.add("stationname");
        columns.add("county");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 条件where
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        strWhere.append(String.format(" and observtime >= '%s'", startT));
        strWhere.append(String.format(" and observtime <= '%s'", t));
        strWhere.append(" and county like '" + DbConfig.CITY + "%'");
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"rain desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<msgmediumsmallscale>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        return resultList;
    }

    @Override
    public qpe_qpf getInitQPFMaxTime() {
        List<qpe_qpf> resultList = new ArrayList<qpe_qpf>();
        // TODO 获取精细化预报最新时间
        qpe_qpf result = new qpe_qpf();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"to_char(datechar,'yyyy-MM-dd HH:mm:ss') as dateChar"};
        selectRequest.setColumns(columns);
        selectRequest.setSort(new String[]{"datechar desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "qpe_qpf");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            result = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<qpe_qpf>>() {
            }).get(0);
        } catch (Exception e) {
            result.setDatechar(DateTime.now().toDate());
        }
        return result;
    }

    @Override
    public List<qpe_qpf> getQPFForecast(String ntimes) {
        List<qpe_qpf> resultList = new ArrayList<qpe_qpf>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
//        List<String> columns = new ArrayList<String>();
        String dateTime = DateTime.now().toDateTimeString("yyyy-MM-dd");
        selectRequest.setParam("datechar>='"+dateTime+"' and ntimes='"+ntimes+"'");
        selectRequest.setSort(new String[]{"datechar desc"});
        selectRequest.setLimit(10);
        try {
            selectParam.put("method", "qpe_qpf");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<qpe_qpf>>() {
            });

        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return resultList;
    }

    @Override
    public List<msgmediumsmallscale> getTempMax(String startT) {
        // TODO 获取自动站--最大温度
        List<msgmediumsmallscale> resultList = new ArrayList<msgmediumsmallscale>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("maxtemp");
        columns.add("timehmaxtemp");
        columns.add("stationname");
        columns.add("county");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 条件where
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        strWhere.append(String.format(" and observtime = '%s'", startT));
        strWhere.append(String.format(" and maxtemp != '%s'", "-65535"));
        strWhere.append(" and city like '" + DbConfig.CITY + "%'");
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"maxtemp desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<msgmediumsmallscale>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        return resultList;
    }

    @Override
    public List<msgmediumsmallscale> getTempMin(String startT) {
        // TODO 获取自动站--最小温度
        List<msgmediumsmallscale> resultList = new ArrayList<msgmediumsmallscale>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("mintemp");
        columns.add("timehmintemp");
        columns.add("stationname");
        columns.add("county");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 条件where
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        strWhere.append(String.format(" and observtime = '%s'", startT));
        strWhere.append(String.format(" and mintemp != '%s'", "-65535"));
        strWhere.append(" and city like '" + DbConfig.CITY + "%'");
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"mintemp asc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<msgmediumsmallscale>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        return resultList;
    }

    @Override
    public List<msgmediumsmallscale> getMaxWind(String startT) {
        // TODO 获取自动站--最大风速
        List<msgmediumsmallscale> resultList = new ArrayList<msgmediumsmallscale>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("hexmaxwindv");
        columns.add("timehmaxwind");
        columns.add("stationname");
        columns.add("county");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 条件where
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        strWhere.append(String.format(" and observtime = '%s'", startT));
        strWhere.append(" and city like '" + DbConfig.CITY + "%'");
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"hexmaxwindv desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<msgmediumsmallscale>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        return resultList;
    }

    @Override
    public List<msgmediumsmallscale> getMinHumid(String startT) {
        // TODO 获取自动站--最小湿度
        List<msgmediumsmallscale> resultList = new ArrayList<msgmediumsmallscale>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("min(relhumidity) as relhumidity");
        columns.add("stationname");
        columns.add("county");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 条件where
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        strWhere.append(String.format(" and observtime = '%s'", startT));
        strWhere.append(" and relhumidity <> -65535 and relhumidity <> 0");
        strWhere.append(" and city like '" + DbConfig.CITY + "%'");
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<msgmediumsmallscale>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        return resultList;
    }

    @Override
    public List<msgmediumsmallscale> getPressMax(String startT) {
        // TODO 获取自动站--最大气压
        List<msgmediumsmallscale> resultList = new ArrayList<msgmediumsmallscale>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("maxstationpress");
        columns.add("timehourmaxpsta");
        columns.add("stationname");
        columns.add("county");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 条件where
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        strWhere.append(String.format(" and observtime = '%s'", startT));
        strWhere.append(String.format(" and maxstationpress != '%s'", "-65535"));
        strWhere.append(" and city like '" + DbConfig.CITY + "%'");
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"maxstationpress desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<msgmediumsmallscale>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        return resultList;
    }

    @Override
    public List<msgmediumsmallscale> getPressMin(String startT) {
        // TODO 获取自动站--最小气压
        List<msgmediumsmallscale> resultList = new ArrayList<msgmediumsmallscale>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("minstationpress");
        columns.add("timehourminpsta");
        columns.add("stationname");
        columns.add("county");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 条件where
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        strWhere.append(String.format(" and observtime = '%s'", startT));
        strWhere.append(String.format(" and minstationpress != '%s'", "-65535"));
        strWhere.append(" and city like '" + DbConfig.CITY + "%'");
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"minstationpress asc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<msgmediumsmallscale>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        return resultList;
    }

    @Override
    public List<traffic> getTrafficPic() {
        // TODO 获取交通预报
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
        Date date = new Date();
        String strDate = format.format(date);
        List<traffic> resultList = new ArrayList<traffic>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("id");
        //columns.add("forecasttime");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        selectRequest.setSort(new String[]{"id desc"});
        selectRequest.setParam(String.format("producttype ='交通预报' and maketime>'%s'", strDate));
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "base_product");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<traffic>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        return resultList;
    }

    @Override
    public List<base_product> getSenlinPic() {
        // TODO 获取森林火险预报
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
        Date date = new Date();
        String strDate = format.format(date);
        List<base_product> resultList = new ArrayList<base_product>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("id");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 条件where
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        strWhere.append(String.format(" and producttype like '%%森林火险预报%%' and maketime>'%s'", strDate));
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());

        selectRequest.setSort(new String[]{"id desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "base_product");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<base_product>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        return resultList;
    }

    @Override
    public List<base_product> getFloodPic() {
        // TODO 获取山洪灾害预报
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
        Date date = new Date();
        String strDate = format.format(date);
        List<base_product> resultList = new ArrayList<base_product>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("id");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 条件where
        StringBuilder strWhere = new StringBuilder();
        strWhere.append(String.format(" producttype = '山洪防汛短期预警'and maketime>'%s'", strDate));
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"id desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "base_product");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<base_product>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        return resultList;
    }

    @Override
    public List<base_product> getDZPic() {
        // TODO 获取地质灾害预报
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
        Date date = new Date();
        String strDate = format.format(date);
        List<base_product> resultList = new ArrayList<base_product>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("id");
        //	columns.add("forecasttime");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 条件where
        StringBuilder strWhere = new StringBuilder();
        strWhere.append(String.format(" producttype = '地质灾害短期预警'and maketime>'%s'", strDate));
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"id desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "base_product");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<base_product>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        return resultList;
    }

    @Override
    public List<base_product> getCityFirePic() {
        // TODO 获取城市火险预报
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
        Date date = new Date();
        String strDate = format.format(date);
        List<base_product> resultList = new ArrayList<base_product>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("id");
        //	columns.add("forecasttime");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 条件where
        StringBuilder strWhere = new StringBuilder();
        strWhere.append(String.format(" producttype = '城市火险预报'and maketime>'%s'", strDate));
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"id desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "base_product");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<base_product>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        return resultList;
    }

    @Override
    public List<base_product> getCityWaterPic() {
        // TODO 获取城市火险预报
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
        Date date = new Date();
        String strDate = format.format(date);
        List<base_product> resultList = new ArrayList<base_product>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("id");
        //	columns.add("forecasttime");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 条件where
        StringBuilder strWhere = new StringBuilder();
        strWhere.append(String.format(" producttype = '城市内涝预报'and maketime>'%s'", strDate));
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"id desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "base_product");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<base_product>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        return resultList;
    }

    @Override
    public List<base_product> getThunderFcstPic() {
        // TODO 获取潜势预报
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
        Date date = new Date();
        String strDate = format.format(date);
        List<base_product> resultList = new ArrayList<base_product>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("id");
        //	columns.add("forecasttime");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 条件where
        StringBuilder strWhere = new StringBuilder();
        strWhere.append(String.format(" producttype = '潜势预报'and maketime>'%s'", strDate));
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"id desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "base_product");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<base_product>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        return resultList;
    }

    @Override
    public List<airpol_fcst> getAirPullutionPic() {
        // TODO 获取空气质量预报
        List<airpol_fcst> resultList = new ArrayList<airpol_fcst>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();

        // 条件where
        StringBuilder strWhere = new StringBuilder();
        strWhere.append(" forecasttype = '24'");
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"datechar desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "airpol_fcst");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<airpol_fcst>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        return resultList;
    }

    /**
     * 获取旅游景点信息
     *
     * @return
     * @author dsq
     * @date 2018年10月22日
     */
    public List<tour_stations> GetTourStaInfo() {
        List<tour_stations> result = new ArrayList<tour_stations>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");
        columns.add("text");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        // 条件where
        StringBuilder strWhere2 = new StringBuilder();
        int whereCount = 0;
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere2.toString())) {
            strWhere2 = strWhere2.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere2.toString());
        try {
            selectParam.put("method", "tour_stations");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            result = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<tour_stations>>() {
            });
        } catch (Exception e) {
            System.out.println("error!");
        }
        return result;
    }

    @Override
    public List<lvyou> getDataTable(String datechar, String timechar) {
        try {
            // TODO 获取旅游数据
            List<lvyou> resultList = new ArrayList<lvyou>();
            List<tour_fcst> fcstResult = new ArrayList<tour_fcst>();
            // List<tour_fcst> result2 = new ArrayList<tour_fcst>();
            List<tour_stations> tourStaList = GetTourStaInfo();
            Map<String, String> selectParam = new HashMap<String, String>();
            RequestDataBySelect selectRequest = new RequestDataBySelect();
            WebCtrlData wcd = new WebCtrlData();
            List<String> columns = new ArrayList<String>();
            columns.add("stationid");
            columns.add("stationname");
            columns.add("weather1");
            columns.add("maxtemp");
            columns.add("mintemp");
            columns.add("winds");
            columns.add("windd");
            columns.add("stationid");
            columns.add("timechar");
            columns.add("to_char(datechar, 'yyyy-MM-dd HH24:MI:SS') as datechar");
            columns.add("ntimes");
            selectRequest.setColumns(columns.toArray(new String[columns.size()]));
            // 条件where
            StringBuilder strWhere = new StringBuilder();
            int whereCount = 0;
            if (datechar != null) {
                strWhere.append(String.format(" and datechar = '%s'", datechar));
            }
            if (timechar != null) {
                strWhere.append(String.format(" and timechar = '%s'", timechar));
            }
            strWhere.append(String.format(" and ntimes<=72 and forecasttype='12'"));
            if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
                strWhere = strWhere.replace(0, 4, "");
            }
            selectRequest.setParam(strWhere.toString());
            selectRequest.setSort(new String[]{"stationid asc", "ntimes asc"});
            try {
                selectParam.put("method", "tour_fcst");
                selectParam.put("sqlType", "select");
                selectParam.put("advCode", DbConfig.advCode);
                selectParam.put("param", JsonUtil.object2Json(selectRequest));
                String message = pc.processRequest(selectParam);
                fcstResult = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<tour_fcst>>() {
                });
            } catch (Exception e) {
                System.out.println("error!");
            }
            if (fcstResult != null && !fcstResult.isEmpty()) {
                // 添加天气预报
                for (int i = 0; i < fcstResult.size() - 1; i+=2) {
                    tour_fcst fcst12 = fcstResult.get(i);
                    tour_fcst fcst24 = fcstResult.get(i + 1);
                    String strStationID = fcst12.getStationid();
                    String strCountyName = fcst24.getStationname();
                    String windD = "";// 风向信息
                    String windV = "";// 风速信息
                    String windD12 = wcd.GetAllFx(fcst12.getWindd().toString().replace("-65535", "0").trim());
                    String windD24 = wcd.GetAllFx(fcst24.getWindd().toString().replace("-65535", "0").trim());
                    String windV12 = String.valueOf(WebCtrlData.FengSuToFengJi(Double.parseDouble(fcst12.getWinds())))
                            + "级";
                    String windV24 = String.valueOf(WebCtrlData.FengSuToFengJi(Double.parseDouble(fcst24.getWinds())))
                            + "级";
                    if (windD12.equals(windD24)) {
                        windD += windD12;
                    } else {
                        windD += windD12 + "转" + windD24;
                    }
                    if (windV12.equals(windV24)) {
                        windV += windV12;
                    } else {
                        windV += windV12 + "转" + windV24;
                    }
                    double maxTemp = fcst12.getMaxtemp() > fcst24.getMaxtemp() ? fcst12.getMaxtemp() : fcst24.getMaxtemp();
                    double minTemp = fcst12.getMintemp() > fcst24.getMintemp() ? fcst24.getMintemp() : fcst12.getMintemp();
                    lvyou fcstInfo = new lvyou();
                    fcstInfo.setStationid(strStationID);
                    fcstInfo.setStationname(strCountyName);
                    fcstInfo.setMintemp(minTemp);
                    fcstInfo.setMaxtemp(maxTemp);
                    fcstInfo.setWindd(windD);
                    fcstInfo.setWinds(windV);
                    fcstInfo.setWeather1(fcst12.getWeather1().trim());
                    fcstInfo.setWeather2(fcst24.getWeather1().trim());
                    for (tour_stations station : tourStaList) {
                        if (station.getStationid().equals(strStationID)) {
                            fcstInfo.setText(station.getText());
                            break;
                        }
                    }
                    resultList.add(fcstInfo);
                }
            }
            return resultList;
        }catch (Exception e){
            throw e;
        }
    }


    @Override
    public forecastinfotemp getThreeDayQBtime() {
        // TODO 获取天气最新时间
        forecastinfotemp result = new forecastinfotemp();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"to_char(datechar,'yyyy-MM-dd 00:00:00') as dateChar", "timechar"};
        selectRequest.setColumns(columns);
        selectRequest.setSort(new String[]{"datechar desc", "timechar desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "forecastinfotemp");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            result = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<forecastinfotemp>>() {
            }).get(0);
        } catch (Exception e) {
            result.setDatechar(DateTime.now().toDate());
        }
        return result;
    }

    @Override
    public List<zhishu> getZhishu() {
        // TODO 获取指数最新时间
        List<zhishu> resultList = new ArrayList<zhishu>();
        zhishu result = new zhishu();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"to_char(datechar,'yyyy-MM-dd 00:00:00') as dateChar",
                "max(timechar) as timechar"};
        selectRequest.setColumns(columns);
        selectRequest.setSort(new String[]{"datechar desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "zhishu");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            result = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<zhishu>>() {
            }).get(0);
        } catch (Exception e) {
            result.setDatechar(DateTime.now().toDate());
            result.setTimechar(DateTime.now().GetHour() >= 8 && DateTime.now().GetHour() < 20 ? "08" : "20");
        }
        Map<String, String> selectParam1 = new HashMap<String, String>();
        RequestDataBySelect selectRequest1 = new RequestDataBySelect();
        // 条件where
        StringBuilder strWhere1 = new StringBuilder();
        int whereCount1 = 0;
        strWhere1.append(String.format(" and datechar = '%s'",
                new DateTime(result.getDatechar()).toDateTimeString("yyyy-MM-dd")));
        strWhere1.append(String.format(" and timechar = '%s'", result.getTimechar().toString().trim()));
        if (whereCount1 == 0 && !StringUtil.IsNullOrEmpty(strWhere1.toString())) {
            strWhere1 = strWhere1.replace(0, 4, "");
        }
        // strWhere1.append(" and cityid like '"+ DbConfig.STATIONSY +"%'");
        selectRequest1.setParam(strWhere1.toString());
        selectRequest1.setLimit(1);
        try {
            selectParam1.put("method", "zhishu");
            selectParam1.put("sqlType", "select");
            selectParam1.put("advCode", DbConfig.advCode);
            selectParam1.put("param", JsonUtil.object2Json(selectRequest1));
            String message1 = pc.processRequest(selectParam1);
            resultList = JsonUtil.jsonStr2TypeReference(message1, new TypeReference<List<zhishu>>() {
            });
        } catch (

                Exception e) {
            e.getMessage();
        }
        return resultList;
    }

    @Override
    public List<warn_signal_info> getSignalInfo() {
        // TODO 得到预警信息
        SimpleDateFormat formate = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        String strDate = formate.format(date) + " 00:00:00";
        List<warn_signal_info> resultList = new ArrayList<warn_signal_info>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"id", "type", "color", "city", "standard", "defenseguide",
                "to_char(announcedtime,'yyyy-MM-dd HH24:MI:SS') as announcedtime", "bfree"};
        selectRequest.setColumns(columns);
        selectRequest.setParam(String.format("announcedtime>='%s'", strDate));//strDate
        selectRequest.setSort(new String[]{"announcedtime desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "warn_signal_info");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<warn_signal_info>>() {
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
        return resultList;
    }

    @Override
    public List<important_weather> GetImpWtInfoTip() {
        // TODO 重要天气
        List<important_weather> resultList = new ArrayList<important_weather>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"stationid", "stationname",
                "to_char(observetime,'yyyy-MM-dd HH24:MI:SS') as observetime", "weathertype", "weatherdetail", "lon",
                "lat"};
        selectRequest.setColumns(columns);
        DateTime date = DateTime.now();
        String strDate1 = date.toDateTimeString("yyyy-MM-dd") + " 00:00:00"; // 开始时间
        String strDate2 = date.toDateTimeString("yyyy-MM-dd") + " 23:59:00"; // 结束时间
        // 条件where
        StringBuilder strWhere = new StringBuilder();
        int whereCount1 = 0;
        if (strDate1 != null) {
            strWhere.append(String.format(" and observetime >= '%s'", strDate1));
        }
        if (strDate2 != null) {
            strWhere.append(String.format(" and observetime <= '%s'", strDate2));
        }
        if (whereCount1 == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "important_weather");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<important_weather>>() {
            });
        } catch (Exception e) {
            e.getMessage();
        }
        return resultList;
    }

    @Override
    public List<warn_signal_info> GetWarnInfoTip() {
        // TODO 预警信号提示版
        List<warn_signal_info> resultList = new ArrayList<warn_signal_info>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        DateTime date = DateTime.now();
        // 条件where
        StringBuilder strWhere = new StringBuilder();
        int whereCount1 = 0;
        strWhere.append(String.format(" and bfree=0"));
        strWhere.append(String.format(" and announcedtime >= '%s'", date.toDateTimeString("yyyy-MM-dd 00:00:00.000")));
        strWhere.append(String.format(" and announcedtime <= '%s'",
                date.AddDays(1).toDateTimeString("yyyy-MM-dd 00:00:00.000")));

        if (whereCount1 == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setLimit(3);
        try {
            selectParam.put("method", "warn_signal_info");
            selectParam.put("sqlType", "select");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<warn_signal_info>>() {
            });
        } catch (Exception e) {
            e.getMessage();
        }
        return resultList;
    }

    @Override
    public List<doppler> getRadarTypes() {
        // TODO 雷达图类型、仰角
        List<doppler> listData = new ArrayList<doppler>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"distinct ldtype", "elevation"};
        selectRequest.setColumns(columns);
        selectRequest.setSort(new String[]{"ldtype", "elevation"});
        try {
            selectParam.put("method", "doppler");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            listData = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<doppler>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        return listData;
    }


    @Override
    public Date getScaleNewDate() {
        // TODO 获取最新实况数据
        Date date = new Date();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String[] columns = new String[]{"to_char(observtime,'yyyy-MM-dd HH24:MI:SS') as observtime"};
        selectRequest.setColumns(columns);
        selectRequest.setParam("stationname like '伊宁%'");
        selectRequest.setSort(new String[]{"observtime desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            date = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<msgmediumsmallscale>>() {
            }).get(0).getObservtime();
        } catch (Exception e) {
            // TODO: handle exception
        }
        return date;
    }

    @Override
    public List<MediumSmallScale> GetHomepagemsg(String time) {
        List<MediumSmallScale> resultList = new ArrayList<MediumSmallScale>();
        List<msgmediumsmallscale> msglist = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setParam(String.format("observtime='%s' and  stationid='" + DbConfig.STATIONID + "'", time));
        selectRequest.setSort(new String[]{"observtime desc"});
        selectRequest.setLimit(1);
        try {
            selectParam.put("method", "msgmediumsmallscale");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            msglist = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<msgmediumsmallscale>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
        }
        WebCtrlData webCtrlData = new WebCtrlData();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if (msglist != null && msglist.size() > 0) {
            for (msgmediumsmallscale msg : msglist) {
                MediumSmallScale smallscale = new MediumSmallScale();
                smallscale.setDateTime(format.format(msg.getObservtime()));

                smallscale.setObservTime(msg.getObservtime());
                smallscale.setStationID(msg.getStationid());
                smallscale.setWindVelocity(msg.getWindvelocity());
                smallscale.setStationName(msg.getStationname());
                smallscale.setRain(msg.getRain());
                smallscale.setDryBulbTemp(msg.getDrybulbtemp());
                smallscale.setInstantWindV(msg.getInstantwindv());
                String s = WebCtrlData.GetAllFx(msg.getInstantwindd()!=null?msg.getInstantwindd().toString():"");
                smallscale.setFX(s);
                smallscale.setRelHumidity(msg.getRelhumidity());
                smallscale.setPressureSea(msg.getPressuresea());
                smallscale.setCity(msg.getCity());
                smallscale.setCounty(msg.getCounty());
                smallscale.setVisibility(msg.getVisibility());
                resultList.add(smallscale);
            }
        }

        return resultList;
    }

    /***
     * 水位监测
     * @return
     */
    @Override
    public List<water_obsrv_sta_info> WeaterStation() {
        List<water_obsrv_sta_info> list = new ArrayList<water_obsrv_sta_info>();
        Map<String, String> selectParam1 = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        selectRequest.setParam("city like '%" + DbConfig.CITY + "%'");
        try {
            selectParam1.put("method", "water_obsrv_sta_info");
            selectParam1.put("sqlType", "select");
            selectParam1.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam1);
            list = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<water_obsrv_sta_info>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return list;
    }

    /***
     * 水位监测曲线图
     * @param startDate
     * @param endDate
     * @param stationname
     * @return
     */
    @Override
    public List<reservoir_water_info> WaterChart(String startDate, String endDate, String stationname) {
        List<reservoir_water_info> dataList = new ArrayList<reservoir_water_info>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("stationid");
        columns.add("stationname");
        columns.add("waterlevel");
        columns.add("observtime");
        columns.add("limited_waterlv");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        selectRequest.setSort(new String[]{"observtime asc"});

        // 拼接where字段
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        if (!StringUtil.IsNullOrEmpty(startDate)) {
            whereCount++;
            strWhere.append(String.format("observtime >='%s'", startDate));
        }
        if (!StringUtil.IsNullOrEmpty(endDate)) {
            strWhere.append(String.format(" and observtime <='%s'", endDate));
        }
        if (stationname != null) {
            strWhere.append(String.format(" and stationname like '%s%%'", stationname));
        }

        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        try {
            selectParam.put("method", "reservoir_water_info");
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<reservoir_water_info>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return dataList;
    }

    /***
     * 获取最近的10条灾害点数据
     * @param zhdPagingModel
     * @return
     */
    @Override
    public List<potential_points> selectZhdByDist(ZhdPagingModel zhdPagingModel) {
        List<potential_points> dataList = new ArrayList<>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        // 获取查询字段
        List<String> columns = new ArrayList<String>();
        columns.add("pp_id");
        columns.add("pp_name");
        columns.add("dis_type");
        columns.add("lon");
        columns.add("lat");
        columns.add("cast(GetDistance(cast(lon as float8),cast(lat as float8),cast(" + zhdPagingModel.getLon() + " as float8),cast(" + zhdPagingModel.getLat() + " as float8)) as numeric(18,1)) dis");
        selectRequest.setColumns(columns.toArray(new String[columns.size()]));
        selectRequest.setLimit(30);
        try {
            selectParam.put("method", "potential_points");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);
            dataList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<potential_points>>() {
            });
        } catch (Exception e) {
            // TODO: handle exception
            System.err.println(e.getStackTrace());
        }
        return dataList;
    }
    @Override
    public Object getTouristProduct(int id, String productType, String startDate, HttpServletRequest request) {
        // TODO Auto-generated method stub
        List<base_product> resultList = new ArrayList<base_product>();
        Map<String, String> selectParam = new HashMap<String, String>();
        RequestDataBySelect selectRequest = new RequestDataBySelect();
        String result = "";
        List<String> list = new ArrayList<>();
        StringBuilder strWhere = new StringBuilder();
        int whereCount = 0;
        String[] columns = new String[]{"to_char(forecasttime, 'yyyy-MM-dd') as forecasttime", "id", "productname", "producttype", "maketime", "maker", "bindid", "context"};
        selectRequest.setColumns(columns);
        if (id > 0) {
            whereCount++;
            strWhere.append(String.format("id=%d", id));
        }
        if (!StringUtil.IsNullOrEmpty(productType)) {
            strWhere.append(String.format("and productType='%s'", productType));
        }
        if (!StringUtil.IsNullOrEmpty(startDate)) {
            strWhere.append(String.format(" and  to_char(forecasttime, 'yyyy-MM-dd')='%s'", startDate));
        }
        if (whereCount == 0 && !StringUtil.IsNullOrEmpty(strWhere.toString())) {
            strWhere = strWhere.replace(0, 4, "");
        }
        selectRequest.setParam(strWhere.toString());
        selectRequest.setSort(new String[]{"forecastTime desc"});
        try {
            selectParam.put("method", "base_product");
            selectParam.put("advCode", DbConfig.advCode);
            selectParam.put("sqlType", "select");
            selectParam.put("param", JsonUtil.object2Json(selectRequest));
            String message = pc.processRequest(selectParam);

            resultList = JsonUtil.jsonStr2TypeReference(message, new TypeReference<List<base_product>>() {
            }, "yyyy-MM-dd");
        } catch (Exception e) {
            // TODO: handle exception
        }
        if (resultList.size() > 0) {
            for (base_product b : resultList) {
                String result1 = "";
                // 处理txt文件
                String urlpath = request.getSession().getServletContext().getRealPath("/") + "Temp\\tourforcast\\";
                FileUtil.mkDirs(urlpath);// 创建文件夹
                // 当文件达到100张时清除
                FileUtil.ClearTempFiles(urlpath, 100);
                String txtType = b.getProductname().split("\\.")[b.getProductname().split("\\.").length - 1];
                // 判断文件类型是否是word
                if (txtType.equals("txt")) {
                    String txtPath = urlpath + b.getProductname();
                    File txtFile = new File(txtPath);
                    if (txtFile.exists()) {
                        result1 = FileUtil.readLogByStringAndEncode(txtPath, "GB2312");
                    } else {
                        // 从mongdo中获取文件
                        Map<String, Object> map = new HashMap<String, Object>();
                        map.put("id", b.getId().toString());
                        map.put("table_name", "base_product");
                        map.put("collectionName", "txt_file");
                        map.put("advCode", DbConfig.advCode);
                        byte[] data = ms.selectData(map);
                        if (data == null) {
                            return "";
                        }
                        // 下载doc文件
                        FileUtil.bytesToFile(data, txtPath);
                        result1 = FileUtil.readLogByStringAndEncode(txtPath, "GB2312");
                    }
                }
                list.add(result1);
            }
        }
        return list;
    }

}
